package com.fw.service.bean;

import java.io.Serializable;
import java.util.Map;
import java.util.Map.Entry;

public class SearchCriteriaBean<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final String DIRECTION_ASC = "ASC";
    public static final String DIRECTION_DESC = "DESC";

    private T criteriaBean;
    private Integer page;
    private Integer size;

    private String order1;
    private String direction1;

    private String order2;
    private String direction2;

    private String order3;
    private String direction3;

    public T getCriteriaBean() {
	return criteriaBean;
    }

    public void setCriteriaBean(T criteriaBean) {
	this.criteriaBean = criteriaBean;
    }

    public Integer getPage() {
	return page;
    }

    public void setPage(Integer page) {
	this.page = page;
    }

    public Integer getSize() {
	return size;
    }

    public void setSize(Integer size) {
	this.size = size;
    }

    public String getOrder1() {
	return order1;
    }

    public void setOrder1(String order1) {
	this.order1 = order1;
    }

    public String getDirection1() {
	return direction1;
    }

    public void setDirection1(String direction1) {
	this.direction1 = direction1;
    }

    public String getOrder2() {
	return order2;
    }

    public void setOrder2(String order2) {
	this.order2 = order2;
    }

    public String getDirection2() {
	return direction2;
    }

    public void setDirection2(String direction2) {
	this.direction2 = direction2;
    }

    public String getOrder3() {
	return order3;
    }

    public void setOrder3(String order3) {
	this.order3 = order3;
    }

    public String getDirection3() {
	return direction3;
    }

    public void setDirection3(String direction3) {
	this.direction3 = direction3;
    }

    public void setSortingCriteria(Map<String, String> sortMap) {
	this.setOrder1(null);
	this.setDirection1(null);
	this.setOrder2(null);
	this.setDirection2(null);
	this.setOrder3(null);
	this.setDirection3(null);
	int index = 0;
	if (sortMap != null && !sortMap.isEmpty()) {
	    for (Entry<String, String> entry : sortMap.entrySet()) {
		if (index == 0) {
		    this.setOrder1(entry.getKey());
		    this.setDirection1(entry.getValue());
		    index++;
		} else if (index == 1) {
		    this.setOrder2(entry.getKey());
		    this.setDirection2(entry.getValue());
		    index++;
		} else if (index == 2) {
		    this.setOrder3(entry.getKey());
		    this.setDirection3(entry.getValue());
		    index++;
		}
	    }
	}
    }

}
